<!DOCTYPE html>
<html>

<head>
  <meta charset="utf-8">
  <title>我要卖</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
  <link rel="stylesheet" href="/statics/layui/css/layui.css" media="all">
</head>

<body>
  <blockquote class="layui-elem-quote">注意：<br /> 1、您当前可买入币种
    <span id="tipTypeId" style="color:green">A</span> 不超过
    <span id="tipMoney" style="color:red">1000</span> ！<br /> 2、需要币种 <span id="tipBuyTypeId" style="color:green">B</span>
    不超过
    <span id="tipBuyMoney" style="color:red">1000</span> ！
  </blockquote>
  <br />
  <form class="layui-form" action="">
    <div class="layui-form-item">
      <div class="layui-inline">
        <label class="layui-form-label">买入数量</label>
        <div class="layui-input-inline" style="width: 100px;">
          <input id="money" type="text" name="money" value="100" lay-verify="required|number" placeholder="￥" autocomplete="off" class="layui-input">
        </div>
      </div>
    </div>
    <div class="layui-form-item">
      <div class="layui-input-block">
        <br />
        <button class="layui-btn" lay-submit="" lay-filter="demo1">立即提交</button>
      </div>
    </div>
  </form>
  <script src="/statics/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="../js/jquery-1.11.0.min.js"></script>
  <script type="text/javascript" src="../js/config.js"></script>
  <script type="text/javascript" src="../js/utils.js"></script>

  <script>
    var id = "", model = null;
    $(function () {
      id = Utils.getUrlParam("id");
      if (!id) {
        window.location.href = "../usercenter.html";
        return;
      }
      getInfo(id, function () {

      });
    });

    layui.use(['form'], function () {
      var form = layui.form, layer = layui.layer;

      //监听提交
      form.on('submit(demo1)', function (data) {
        var json = data.field;
        json.sellId = id;

        var typeName = $("#tipTypeId").text();
        layer.confirm('确定要买入 '+json.money+' ('+typeName+') 吗?', {icon: 3, title:'提示'}, function(index){
          var url = Config.WEB_SERVER_API + Config.URI.USER_MONEY_BUY_SAVE;
          HttpUtils.httpPost(url, json, function (result, success) {
            if (success) {
              layer.alert('恭喜您，买入成功！', { title: '提示' }, function(index){
                window.parent.location.reload();
              });
            } else {
              layer.alert(result.resultMsg, { title: '出错了', icon: 5 });
            }
          });
          layer.close(index);
        });
        return false;
      });

      //表单初始赋值
      // form.val('example', {"money":100});
    });

    var getInfo = function (id, callback) {
      DataUtils.getUserMoneyCellInfo(id, function (data) {
        if (!data) {
          window.location.href = "../usercenter.html";
          return;
        }
        model = data;
        $("#tipTypeId").text(data.typeName);
        $("#tipBuyTypeId").text(data.buyTypeName);
        $("#tipMoney").text(data.leaveMoney);
        $("#tipBuyMoney").text(data.leaveMoney);
        $("#money").val(data.leaveMoney);
        if (callback) {
          callback();
        }
      });
    };
  </script>

</body>

</html>